package com.okex.open.api;

import com.okex.open.api.utils.DateTimeUtils;
import com.okex.open.api.utils.DateUtils;
import com.okex.open.api.utils.DateUtils1;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

public class CyclicBarrierTest extends TradeAPIBaseTest{

    /**
     * 获取指定时间对应的毫秒数
     *
     * @param time "HH:mm:ss"
     * @return
     */
    private static long getTimeMillis(String time)
    {
        try
        {
            DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss:SSS");
            DateFormat dayFormat = new SimpleDateFormat("yy-MM-dd");
            Date curDate = dateFormat.parse(dayFormat.format(new Date()) + " " + time);
            return curDate.getTime();
        }
        catch (ParseException e)
        {
        }
        return 0;
    }
    public static void main(String[] args) {
//        PublicAPITest publicAPITest = new PublicAPITest();
//        publicAPITest.before();
//        System.out.println("okex systime"+DateTimeUtils.formatDateTimeString(Long.valueOf(publicAPITest.getSystemTime())));
        System.out.println("okex抢币客户端启动");
        TradeAPITest tradeAPITest = new TradeAPITest();
        tradeAPITest.before();
        long oneDay = 24 * 60 * 60 * 1000;
        long initDelay = getTimeMillis(args[0]) - System.currentTimeMillis()-Long.valueOf(args[1]);//提前多少毫秒
        initDelay = initDelay > 0 ? initDelay : oneDay + initDelay;
        ScheduledExecutorService ses = Executors.newScheduledThreadPool(60);
        long initvalue = 250;
        long[] arrray =new long[60];
        for(int i =0;i<arrray.length;i++){
            arrray[i]=initvalue;
            initvalue+=20;
        }
        //1
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay,oneDay,TimeUnit.MILLISECONDS);
        //2
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[0],oneDay,TimeUnit.MILLISECONDS);
        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[1],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[2],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[3],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[4],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[5],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[6],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[7],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[8],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[9],oneDay,TimeUnit.MILLISECONDS);
        //11
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[10],oneDay,TimeUnit.MILLISECONDS);

        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[11],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[12],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[13],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[14],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[15],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[16],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[17],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[18],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[19],oneDay,TimeUnit.MILLISECONDS);
        //11
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[20],oneDay,TimeUnit.MILLISECONDS);

        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[21],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[22],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[23],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[24],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[25],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[26],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[27],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[28],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[29],oneDay,TimeUnit.MILLISECONDS);
        //11
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[30],oneDay,TimeUnit.MILLISECONDS);

        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[31],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[32],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[33],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[34],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[35],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[36],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[37],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[38],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[39],oneDay,TimeUnit.MILLISECONDS);
        //11
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[40],oneDay,TimeUnit.MILLISECONDS);

        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[41],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[42],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[43],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[44],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[45],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[46],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[47],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[48],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[49],oneDay,TimeUnit.MILLISECONDS);
        //11
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[50],oneDay,TimeUnit.MILLISECONDS);
        //3
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[51],oneDay,TimeUnit.MILLISECONDS);
        //4
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[52],oneDay,TimeUnit.MILLISECONDS);
        //5
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[53],oneDay,TimeUnit.MILLISECONDS);
        //6
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[54],oneDay,TimeUnit.MILLISECONDS);
        //7
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[55],oneDay,TimeUnit.MILLISECONDS);
        //8
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[56],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[57],oneDay,TimeUnit.MILLISECONDS);
        //9
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[58],oneDay,TimeUnit.MILLISECONDS);
        //10
        ses.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                tradeAPITest.placeOrderBuy();
            }
        }, initDelay+arrray[59],oneDay,TimeUnit.MILLISECONDS);

    }

}
